<template>
  <div class="RealWarning">
    <div class="title">实时预警</div>
    <div class="swiper" v-if="data?.length">
      <swiper
        :options="swiperOption"
        :not-next-tick="notNextTick"
        ref="mySwiper"
      >
        <swiper-slide v-for="(item, index) in data" :key="index">
          <div class="item">
            <div class="top">{{ item.activeObject.cameraAddr }}</div>
            <img
              :src="'/httpImage/' + item.list[0].targetInfo[0].picSmUrl"
              @click="rightBlock2(index)"
            />
            <div class="bottom">
              <span>{{ item.activeObject.otherLabels }}</span>
              <span>{{
                $moment(item.activeObject.picDate).format("HH:mm:ss")
              }}</span>
            </div>
          </div>
        </swiper-slide>
      </swiper>
      <PreviewImageDialog ref="PreviewImageDialog"></PreviewImageDialog>
    </div>
  </div>
</template>
<script>
import { swiper, swiperSlide } from "vue-awesome-swiper";
import PreviewImageDialog from "@/components/dialog/PreviewImageDialog";

import { rtCapture } from "@/api/panoramicData";
let timer = null;
export default {
  components: {
    swiper,
    PreviewImageDialog,
    swiperSlide,
  },
  computed: {
    swiper() {
      return this.$refs.mySwiper.swiper;
    },
  },
  mounted() {
    this.runRtCapture();
  },
  beforeDestroy() {
    timer && clearInterval(timer);
  },
  data() {
    return {
      data: [],
      editConfig: {
        visible: false,
        infomation: [],
        personIndex: 0,
        currentId: "",
        isLookImg: false,
        tabs: [],
      },
      notNextTick: false,
      swiperOption: {
        autoplay: {
          delay: 2000,
        },
        loop: true,
        direction: "horizontal",
        spaceBetween: 20,
        slidesPerView: 7,
        // prevButton: '.swiper-button-prev',
        // nextButton: '.swiper-button-next',
        slidesOffsetBefore: 20,
        slidesOffsetAfter: 20,
      },
    };
  },
  methods: {
    rightBlock2(index) {
      this.$refs.PreviewImageDialog.add(this.data, index);
    },
    runRtCapture() {
      rtCapture().then((res) => {
        this.data = res.data?.datalist;
      });
      timer = setInterval(() => {
        rtCapture().then((res) => {
          this.data = res.data?.datalist;
        });
      }, 60000);
    },
  },
};
</script>
<style lang="scss" scoped>
.RealWarning {
  width: 100%;
  height: 100%;
  background-image: url("/public/panoramicData//warningBox.png");
  background-size: contain;
  position: relative;

  .title {
    font-size: 30px;
    font-weight: bold;
    line-height: 40px;
    padding-left: 46px;
    color: #01c2ff;
  }

  .swiper {
    height: 220px;
    width: 100%;
    margin-top: 30px;
  }

  .item {
    height: 220px;
    text-align: center;
    width: 175px;
    color: #fff;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    img {
      height: 175px;
      width: 175px;
      object-fit: cover;
    }
    .top {
      height: 24px;
      line-height: 24px;
      background-color: rgba(46, 94, 171, 1);
    }

    .bottom {
      height: 24px;
      line-height: 20px;
      padding: 0px 10px;
      box-sizing: border-box;
      background-color: rgba(46, 94, 171, 1);
    }
  }
}
</style>
